package com.heima.comment.controller;

import com.heima.comment.service.CommentService;
import com.heima.model.comment.dtos.CommentDTO;
import com.heima.model.comment.dtos.CommentLikeDTO;
import com.heima.model.comment.dtos.CommentSaveDTO;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
@Api("评论接口")
public class CommentController {
    @Autowired
    private CommentService commentService;
    /**
     * 保存评论
     * @param dto
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存评论",tags = "保存评论")
    public ResponseResult saveComment(@RequestBody  @Validated CommentSaveDTO dto){
        return commentService.saveComment(dto);

    }

    /**
     * 评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @ApiOperation(value = "点赞评论",tags = "点赞评论")
    public ResponseResult likeComment(@RequestBody  @Validated CommentLikeDTO dto){
        return commentService.like(dto);
    }

    ///api/v1/comment/load

    /**
     * 评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation(value = "评论列表加载",tags = "评论列表加载")
    public ResponseResult loadCommentList(@RequestBody  @Validated CommentDTO dto){
        return commentService.findByArticleId(dto);
    }
}
